package com.leoman.plz_p.weidget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.leoman.plz_p.R;

/**
 * Created by guoh on 2018/7/3.
 */
public class CommonDialog extends Dialog {
    TextView tvTitle;
    TextView tvMessage;
    TextView tvKnow;
    TextView tvCancel;
    View line;


    public CommonDialog(@NonNull Context context) {
        super(context);
    }

    public CommonDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.DialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_common_dialog);
        tvKnow=findViewById(R.id.tv_know);
        tvMessage=findViewById(R.id.tv_message);
        tvTitle=findViewById(R.id.tv_title);
        tvCancel=findViewById(R.id.tv_cencel);
        line=findViewById(R.id.v_line);
        Window win = getWindow();
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.gravity = Gravity.CENTER;
        win.setAttributes(lp);

    }

    public void setLogoutStyle(){
        line.setVisibility(View.VISIBLE);
        tvCancel.setVisibility(View.VISIBLE);
        tvKnow.setTextColor(getContext().getResources().getColor(R.color.colorPrimary));
        tvCancel.setTextColor(getContext().getResources().getColor(R.color.colorPrimary));
        tvTitle.setVisibility(View.GONE);
        tvMessage.setTextColor(Color.BLACK);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        tvKnow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        tvCancel.setText("取消");
        tvKnow.setText("确定");
    }
    public void setCancelText(String text){
        if (!TextUtils.isEmpty(text)){
            tvCancel.setText(text);
        }
    }

    public void setTitle(String title){
        if (!TextUtils.isEmpty(title)){
            tvTitle.setText(title);
        }
    }

    public void setMessage(String message){
        if (!TextUtils.isEmpty(message)){
            tvMessage.setText(message);
        }
    }

    public void setKnowCLickListener(View.OnClickListener listener){
        if (listener!=null){
            tvKnow.setOnClickListener(listener);
        }
    }
}
